package com.itheima.sfbx.insurance.web;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.SafeguardVO;
import com.itheima.sfbx.insurance.service.ISafeguardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Desctiption: 保障响应接口
 */
@Slf4j
@Api(tags = "保障项")
@RestController
@RequestMapping("/safeguard")
public class SafeguardController {

    @Autowired
    private ISafeguardService safeguardService;

    /**
     * @param safeguardVO 查询条件
     * @param pageNum     当前页码
     * @param pageSize    每页显示数量
     * @return 封装的分页数据
     */
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页查询保障项", notes = "分页查询保障项")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, dataType = "int", paramType = "path", example = "1"),
            @ApiImplicitParam(name = "safeguardVO", value = "查询条件", required = true, dataType = "SafeguardVO")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.dataState", "safeguardVO.safeguardKey", "safeguardVO.safeguardKeyName", "safeguardVO.safeguardVal", "safeguardVO.safeguardType", "safeguardVO.sortNo", "safeguardVO.remake"})
    public ResponseResult<Page<SafeguardVO>> findSafeguardVOPage(
            @RequestBody SafeguardVO safeguardVO,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ) {
        Page<SafeguardVO> safeguardVOPage = safeguardService.findPage(safeguardVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(safeguardVOPage);
    }

    /**
     * 创建保障项
     *
     * @param safeguardVO
     * @return
     */
    @PutMapping
    @ApiOperation(value = "创建保障项", notes = "创建保障项")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "safeguardVO", value = "保障项信息", required = true, dataType = "SafeguardVO")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.id", "safeguardVO.dataState", "safeguardVO.safeguardKey", "safeguardVO.safeguardKeyName", "safeguardVO.safeguardVal", "safeguardVO.safeguardType", "safeguardVO.sortNo", "safeguardVO.remake"})
    public ResponseResult<SafeguardVO> createSafeguard(@RequestBody SafeguardVO safeguardVO) {
        SafeguardVO createSafeguardVO = safeguardService.save(safeguardVO);
        return ResponseResultBuild.successBuild(createSafeguardVO);
    }

    /**
     * 更新保障项
     * @param safeguardVO 修改的保障项
     * @return 修改结果
     */
    @PatchMapping
    @ApiOperation(value = "更新保障项", notes = "更新保障项")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "safeguardVO", value = "保障项信息", required = true, dataType = "SafeguardVO")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.id", "safeguardVO.dataState", "safeguardVO.safeguardKey", "safeguardVO.safeguardKeyName", "safeguardVO.safeguardVal", "safeguardVO.safeguardType", "safeguardVO.sortNo", "safeguardVO.remake"})
    public ResponseResult<Boolean> updateSafeguard(@RequestBody SafeguardVO safeguardVO) {
        Boolean result = safeguardService.update(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 更新保障项
     * @param safeguardVO 修改的保障项
     * @return 修改结果
     */
    @DeleteMapping
    @ApiOperation(value = "删除保障项", notes = "删除保障项")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "safeguardVO", value = "保障项信息", required = true, dataType = "SafeguardVO")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.id", "safeguardVO.dataState", "safeguardVO.safeguardKey", "safeguardVO.safeguardKeyName", "safeguardVO.safeguardVal", "safeguardVO.safeguardType", "safeguardVO.sortNo", "safeguardVO.remake"})
   public ResponseResult<Boolean> deleteSafeguard(@RequestBody SafeguardVO safeguardVO) {
        Boolean result = safeguardService.delete(safeguardVO.getCheckedIds());
        return ResponseResultBuild.successBuild(result);
    }

    @PostMapping("/list")
    public ResponseResult<List<SafeguardVO>> findSafeguardVOList(@RequestBody SafeguardVO safeguardVO) {
        List<SafeguardVO> list = safeguardService.findList(safeguardVO);
        return ResponseResultBuild.successBuild(list);
    }



}
